<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>会编程的酷基</title>
		<script src="js/jquery-3.2.1.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="root">
			<h1>会编程的酷基-群书籍共享抽奖程序</h1><br />
			<span>抽奖物品:</span>&nbsp;&nbsp;<input type="text" id="good" readonly="readonly" />&nbsp;&nbsp;<br />
			<span>请输入你的QQ号:</span>&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="" id="qq" value="" />&nbsp;&nbsp;
			<input type="button" name="btn" id="btn" value="提交" />
		</div>
		<script type="text/javascript">
			var BaseUrl = "http://127.0.0.1:8090/";
			$.ajax({
				url: BaseUrl+"getGood",
				success: function(data) {
					if (data.status == 200) {
						var good = data.data;
						$("#good").attr("goodid", good.id);
						$("#good").val(good.name);
					} else {
						alert(data.msg)
					}
				}
			});
			var fun = function() {
				var qq = $("#qq").val().trim();
				var reg = /^[1-9]\d{3,9}$/;
				if(reg.test(qq)){
					var goodid = $("#good").attr("goodid");
					$.ajax({
						url: BaseUrl+"insertPerson",
						type:"POST",
						data: {
							"qq": qq,
							"id": goodid
						},
						success: function(data) {
							if(data.status == 200){
								alert("报名成功");
							}else{
								alert("报名失败,"+data.msg);
							}
							$("#qq").val("");
						}
					})
				}else{
					alert("请输入正确的qq号");
				}
			};
			$("#btn").on("click", fun);
		</script>
	</body>
</html>
